package com.xia.controller;

import com.xia.domian.Chat;
import com.xia.service.IChatService;
import com.xia.util.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RestController
@RequestMapping("/chat")
public class ChatController {
    private IChatService chatService;
    @Autowired
    public void setChatService(IChatService chatService) {
        this.chatService = chatService;
    }

    /**
     * 获取聊天内容
     */
    @GetMapping("/getChatContent/{chatKey}/{usersId}")
    public Result getChatContent(@PathVariable String chatKey,@PathVariable Integer usersId){
        return (Result) chatService.getChatContentAndByUser(chatKey,usersId);
    }

    /**
     * 获取用户的聊天对象
     */
    @GetMapping("/getChatUser/{usersId}")
    public Result getChatUser(@PathVariable Integer usersId){
        return Result.success(chatService.selectUsersChatMsg(usersId));
    }

    /**
     * 点击私信进行交流
     */
    @PostMapping("/toChat/{forUsersId}/{usersId}")
    public Result toChat(@PathVariable Integer forUsersId,@PathVariable Integer usersId){
        return Result.success(chatService.privateLetter(usersId,forUsersId));
    }

    /**
     * 用户之间进行交流
     */
    @PostMapping("/inTheChat")
    public Result inTheChat(@RequestBody Chat chat) throws Exception {
        chatService.userOnTheChat(chat);
        return Result.success();
    }
}
